package ag.carnot.pinkblob.web.jsf.beans.pinkblob.issueinvoice;

import ag.carnot.web.jsf.common.structureddata.ComplexTypeWrapper;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.validator.ValidatorException;

import org.apache.log4j.Logger;

import pinkblob.log.Log;

public class CreateAdmonitionCommentBean {

	private static Logger log = new Log().getLogger(CreateAdmonitionCommentBean.class);

	public void complete() {

		// variables that have to be filled for completion
		String comment = (String) getProjectInformation().get(
				"II_AdmonitionMailComment");

		log.info("Comment " + comment);

		// create message to display
		FacesMessage msg = new FacesMessage();
		String summary = "";

		if (comment == null || comment.trim().equals("")) {
			summary = summary + " You are required to set a comment!";
		}
		if (!(summary.equals(""))) {
			log.error(summary);
			msg.setSummary(summary);
			throw new ValidatorException(msg);
		}
	}

	private ComplexTypeWrapper projectInformationWrapper = new ComplexTypeWrapper(
			"ProjectInformation", null);

	public ComplexTypeWrapper getProjectInformationWrapper() {
		return projectInformationWrapper;
	}

	@SuppressWarnings("unchecked")
	public Map getProjectInformation() {
		return (Map) projectInformationWrapper.getComplexType();
	}

	@SuppressWarnings("unchecked")
	public void setProjectInformation(Map projectInformation) {
		projectInformationWrapper = new ComplexTypeWrapper(
				projectInformationWrapper.getDataMappingId(),
				projectInformation);
	}
}
